package view;

import java.awt.CardLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import model.map.ViewMap;

import view.listeners.AcceptListener;
import view.listeners.BackListener;
import view.listeners.BuyListener;
import view.listeners.CancelListener;
import view.listeners.ContinueListener;
import view.listeners.ExitListener;
import view.listeners.NewGameListener;
import view.listeners.PauseExitListener;
import view.listeners.PauseListener;
import view.listeners.ResetListener;
import view.listeners.SellListener;
import view.listeners.ToControllerConfigMenuListener;
import view.listeners.ToOccupationChooserListener;


/**
 * This class holds all the information of how to render  the view.
 * this will need to either be called from the main function or be added
 * to the main function.
 * 
 * @author Stephanie
 *
 */
public class GUITest {

	public static void startGUI(ViewMap viewMap) {
		
		MainFrame mainFrame = new MainFrame("Medusa");
		
		InventoryPanel inventoryPanel = new InventoryPanel();
		MapPanel mapPanel = new MapPanel();
		PausePanel pausePanel = new PausePanel();
		EquipmentPanel equipPanel = new EquipmentPanel();
		SkillsPanel skillsPanel = new SkillsPanel();
		StatsPanel statsPanel = new StatsPanel();
		Terminal terminal = new Terminal();
		boolean newGame = false;
		
		JPanel[] panels = new JPanel[] { inventoryPanel, mapPanel, pausePanel, equipPanel, skillsPanel, statsPanel };
		
		GamePanel gp = new GamePanel( panels );
		MainMenu menu = new MainMenu( mainFrame );
		ControllerConfigMenu configMenu = new ControllerConfigMenu( mainFrame );
		OccupationChooserMenu occupationMenu = new OccupationChooserMenu( mainFrame );
		PauseMenu pauseMenu = new PauseMenu();
		pauseMenu.setVisible(false);
		//LevelUpMenu levelUpMenu = new LevelUpMenu();
		//levelUpMenu.setVisible(false);
		//MerchantInteractionMenu merchantMenu = new MerchantInteractionMenu(null,null);
		gp.add(terminal);
		
		NewGameListener newGameListener = new NewGameListener( mainFrame );
		ExitListener exitListener = new ExitListener();
		ToControllerConfigMenuListener toControllerConfigListener= new ToControllerConfigMenuListener( mainFrame );
		ToOccupationChooserListener toOccupationChooserListener = new ToOccupationChooserListener( mainFrame, newGame );
		AcceptListener acceptListener = new AcceptListener( mainFrame );
		ResetListener resetListener = new ResetListener();
		CancelListener cancelListener = new CancelListener( mainFrame );
		BackListener backListener = new BackListener( mainFrame );
		PauseListener pauseListener = new PauseListener( gp, pauseMenu );
		//SaveListener saveListener = new SaveListener();
		//LoadListener loadListener = new LoadListener();
		ContinueListener continueListener = new ContinueListener( pauseMenu );
		PauseExitListener pauseExitListener = new PauseExitListener( mainFrame, pauseMenu );
		BuyListener buyListener = new BuyListener();
		SellListener sellListener = new SellListener();
		
		
		
		menu.addNewGameListener(toOccupationChooserListener);
		menu.addChangeControllerListener(toControllerConfigListener);
		menu.addExitListener(exitListener);
		//menu.addLoadListener(loadListener);
		
		occupationMenu.addNewGameListener(newGameListener);
		occupationMenu.addBackListener(backListener);
		
		configMenu.addAcceptListener( acceptListener );
		configMenu.addResetListener( resetListener );
		configMenu.addCancelListener( cancelListener );
		
		pausePanel.addPauseListener( pauseListener );
		
		//pauseMenu.addSaveListener( saveListener );
		pauseMenu.addContinueListener( continueListener );
		pauseMenu.addExitListener( pauseExitListener );
		
		mainFrame.add( gp, "GAME_PANEL");
		mainFrame.add( menu, "MAIN_MENU");
		mainFrame.add( configMenu, "CONTROLLER_CONFIG_MENU");
		mainFrame.add( occupationMenu, "OCCUPATION_CHOOSER_MENU");
		
		mainFrame.changeActivePanel("MAIN_MENU");
		
		
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mapPanel.setMap(viewMap);
		//mapPanel.refresh();
		
	}
	
	
}
